//
//  Delegate.m
//  BeautifulWardrobe
//
//  Created by mac on 16/7/29.
//  Copyright © 2016年 Yh. All rights reserved.
//

#import "Delegate.h"

@implementation Delegate

- (id)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame])
    {
        self.frame = CGRectMake(0, 64,[UIScreen mainScreen].bounds.size.width, 44);
        self.layer.borderWidth = 1;
        self.layer.borderColor = [[UIColor grayColor]CGColor];
        [self getViewScrollViewAndButton];
    }
    return self;
}
- (void)getViewScrollViewAndButton
{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(self.bounds.size.width-35, 10 , 20, 20);
    [button setBackgroundImage:[UIImage imageNamed:@"image_more_down"] forState:UIControlStateNormal];
    [self addSubview:button];
}

- (void)getRequestUrl:(NSString *)string
{
    AFHTTPSessionManager * manager = [Session getSessionManage];
    [manager GET:string parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary * objecDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSDictionary * dataDic = objecDic[@"data"];
        NSArray * floorArray = dataDic[@"floor_items"];
        NSString * textStr = dataDic[@"search_text"];
        for (NSDictionary * floorDic in floorArray)
        {
            NSMutableArray * titleArray = [[NSMutableArray alloc]init];
            NSLog(@"%@",floorDic);
            NSString * titleStr= floorDic[@"title"];
            [titleArray addObject:titleStr];
            [self.delegate getHeadStr:textStr];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
- (void)getScrollViewButtonUrl:(NSString *)string
{
    AFHTTPSessionManager * manager = [Session getSessionManage];
    [manager GET:string parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        __block NSMutableArray * array = [[NSMutableArray alloc]init];
        NSDictionary * objectDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSDictionary  * dataDict = objectDic[@"data"];
        NSArray * floorArray =dataDict[@"floor_items"];
        for (NSDictionary * dataDic in floorArray)
        {
            NSString * str = dataDic[@"title"];
            [array addObject:str];
        }
        [self.delegate getButtonTitle:array];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
